#!/usr/bin/env bash

SCRIPT="$0"
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
while [ -h "$SCRIPT" ] ; do
  ls=`ls -ld "$SCRIPT"`
  # Drop everything prior to ->
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    SCRIPT="$link"
  else
    SCRIPT=`dirname "$SCRIPT"`/"$link"
  fi
done

SRC_HOME=`dirname "$SCRIPT"`
export SRC_HOME=`cd "$SRC_HOME"; pwd`
cd $SRC_HOME
rm -rf dist/*
npm install
npm run build
mkdir -p dist/share
mkdir -p dist/error
mkdir -p dist/diff
cp dist/index.html dist/share
cp dist/index.html dist/error
cp dist/index.html dist/diff
